<?php
namespace app\admins\controller;
use think\captcha\CaptchaController;
use think\Controller;
use think\queue\job\Redis;
use think\Request;
use Util\data\Sysdb;
use app\admins\model\Admins;
use think\cache\driver\Redis as tp_redis;

/**
* 
*/
class Test extends Controller
{

    public function _initialeze()
    {
        parent::_initialeze();
    }

    public function test()
    {
        $options = [
            'host'       => '192.168.0.44',
            'port'       => 6379,
            'password'   => '',
            'select'     => 0,
            'timeout'    => 0,
            'expire'     => 0,
            'persistent' => false,
            'prefix'     => '',
        ];

        $tp_redis = new tp_redis($options);
        $aa = json_encode($options);
//        $tp_redis->set('test',$tp_redis);
        dump($tp_redis->get('name'));


        $user = Admins::get(1);
        echo $user->username; // 例如输出“正常”

//        $user->username = 'THINKPHP';
//        $user->save();
//        echo $user->username; // thinkphp

        // 软删除
//        Admins::destroy(1);



    }


    public function index(){
        $this->db = new Sysdb();
        $res = $this->db->table('admins')->field('id,username')->lists();
        dump($res);
        $res = $this->db->table('admins')->field('id,username')->cates('id');
        dump($res);
	}
	public function setPwd(){
	    $Admins = new Admins;
        dump($Admins->save(['password'=>md5('admin111')],['username'=>'admin']));
	    dump(md5("admin11"));
	    return;
    }
    public function getmd5(){
        dump(md5("123456"));

    }
    public function indexS(){
	    return $this->fetch('');
    }
    public function hookTest(){
        $params = "hookTest";
        \think\Hook::add('appInit','app\admins\behavior\Test');
        \think\Hook::add('myTage','app\admins\behavior\Test');
        \think\Hook::listen('appInit',$params);//参数为变量(下同)
        \think\Hook::listen('myTage',$params);//参数为变量(下同)


        Request::hook('user','getUserInfo');
        $userId = '222';
//        方法注入
        $info = Request::instance()->user($userId);
//        $redis = new Redis();
//        $redis->connect('127.0.0.1',6379);
//        $redis->set('name','leesin');
//        echo $redis->get('name');


        //实例化redis
//        $redis = new Redis();

//        连接
//        $redis->connect('127.0.0.1', 6379);
        //检测是否连接成功
//        echo "Server is running: " . $redis->ping();
        // 输出结果 Server is running: +PONG
    }
}